package adapter;

import java.util.ArrayList;

import com.activity.MainAppActivity;
import com.activity.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterMenu extends ArrayAdapter<entities.MenuItem> {
	private Context context;
	private int resId;
	private ArrayList<entities.MenuItem> arrayList;

	public AdapterMenu(Context context, int resource,
			ArrayList<entities.MenuItem> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resId = resource;
		this.arrayList = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Log.d("---AdapterMenu", "getView inselected:"
				+ arrayList.get(position).isSelected());

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(resId, null);
		if (arrayList.get(position).isSelected())
			convertView.setBackgroundColor(context.getResources().getColor(
					R.color.main_blue));

		ImageView image = (ImageView) convertView.findViewById(R.id.menu_img);
		TextView txtName = (TextView) convertView
				.findViewById(R.id.txt_menu_name);
		txtName.setTypeface(MainAppActivity.typeFaceFont);
		image.setImageResource(arrayList.get(position).getImgRes());
		txtName.setText(context.getResources().getString(
				arrayList.get(position).getNameRes()));
		return convertView;
	}
}
